package com.googlecode.boliang.q05.a;

import java.util.Iterator;
import java.util.TreeSet;

public class LeastKNumbers {
	
	private TreeSet<Integer> treeSet = new TreeSet<Integer>(); 
	
	public void getLeastKNumber(int[] intArray, int k) {
		
		for (int i : intArray) {
			
			if(treeSet.size() < k) {
				
				treeSet.add(i); 
			} else {
				
				if (k < treeSet.last()) {
					treeSet.remove(treeSet.last()); 
					treeSet.add(i); 
				}
			}
		}
		
		for (Iterator<Integer> iter = treeSet.iterator(); iter.hasNext(); ) {
			System.out.println(iter.next()); 
		}
		
	}

}
